package com.wpw.dream.thread;


import java.util.concurrent.atomic.AtomicInteger;

/**
 * volatile关键字不具备synchronized关键字的原子性（同步）
 * @author alienware
 *
 */
public class ValitileNotAtomic extends Thread{
//	private static volatile int count;
	private static AtomicInteger count = new AtomicInteger(0);
	private static void addCount(){
		for (int i = 0; i < 1000; i++) {
			//synchronized (ValitileNotAtomic.class) {
				
//				count = count+1 ;
			//}
			count.incrementAndGet();
		}
		System.out.println(count);
	}
	
	public void run(){
		addCount();
	}
	
	public static void main(String[] args) {
		
		ValitileNotAtomic[] arr = new ValitileNotAtomic[100];
		for (int i = 0; i < 10; i++) {
			arr[i] = new ValitileNotAtomic();
		}
		
		for (int i = 0; i < 10; i++) {
			arr[i].start();
		}
	}
	
	
	
	
}
